#!/usr/bin/env python
# -*- coding:utf8 -*-
# uncompyle6 version 2.15.1
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.10 (default, Jul  1 2017, 13:36:56) 
# [GCC 4.4.6 20110731 (Red Hat 4.4.6-4)]
# Embedded file name: ./login/healthz/views.py
# Compiled at: 2017-11-16 15:44:28
import os
from django.http import JsonResponse, HttpResponse
from django.conf import settings
from bkaccount.decorators import login_exempt

@login_exempt
def healthz(request):
    """
    health check
    """
    try:
        settings.ESB_TOKEN
        data = {'debug': settings.DEBUG,
           'env': os.getenv('BK_ENV', 'unknow'),
           'cookie_domain': settings.BK_COOKIE_DOMAIN,
           'mysql': {'host': settings.DATABASES.get('default', {}).get('HOST'),
                     'port': settings.DATABASES.get('default', {}).get('PORT'),
                     'user': settings.DATABASES.get('default', {}).get('USER'),
                     'database': settings.DATABASES.get('default', {}).get('NAME')
                     }
           }
    except Exception as e:
        return HttpResponse(u'配置文件不正确, 缺失对应配置: %s' % str(e), status=500)

    try:
        from bkaccount.models import BkUser
        objs = BkUser.objects.all()
        [ o.username for o in objs ]
    except Exception as e:
        return HttpResponse(u'数据库连接存在问题: %s' % str(e), status=500)

    return JsonResponse({'result': True}, status=200)
